﻿using System;
using Newtonsoft.Json;
using WPFNote.Models.Config;

namespace WPFNote.Utilities;

public class Config
{
    private static Config _instance = null;

    public BooleanParam BooleanParam { get; set; }
    public TencentCloudParam TencentCloudParam { get; set; }
    
    public static Config Init()
    {
        return _instance ??= new Config();
    }

    public void JsonParse(string json)
    {
        try
        {
            _instance = JsonConvert.DeserializeObject<Config>(json);
        }
        catch
        {
            Init();
        }
    }

    public string JsonStringify()
    {
        return _instance == null ? string.Empty: JsonConvert.SerializeObject(_instance);
    }
}